package com.diandi.signature.controller.contract;


import com.diandi.signature.contract.SignatureContractService;

import com.diandi.signature.properties.FddProperties;
import com.diandi.signature.properties.SignatureProperties;
import com.diandi.signature.utils.CallServiceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 测试服务类
* @author mwz
* @create 2017-08-23 10:11
* @version V1.0.0
*/
@Controller
@RequestMapping("/testContract")
public class TestContractController {
    private static Logger logger = LoggerFactory.getLogger(TestContractController.class);

    @Autowired
    private SignatureProperties signatureProperties;
    @Autowired
    private FddProperties fddProperties;

   @Autowired
    private SignatureContractService signatureContractService;




    //建立一个工作线程池
    public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(1000);


    @RequestMapping("/contract")
    @ResponseBody
    public void processSignature () {

        logger.info("--------------------------------- Start -------------------------------");
        for(int i=1;i<1000 ;i++ ){

            logger.info("--------------------------------- process("+i+") -------------------------------");
            fixedThreadPool.execute(new Runnable( ) {
                @Override
                public void run() {
                            task();
                    }
             });

         }
        logger.info("--------------------------------- End -------------------------------");
    }

    public void task(){
        long idx =0L;
        while(true){
            String url = "http://localhost:8080/getUserInfo";
            String pgkMsg = "";
            String result = CallServiceUtil.sendPost(url,pgkMsg);
            idx++;
            System.out.println(Thread.currentThread().getName()+"_"+"idx:"+idx+"--");
            logger.info("-----"+Thread.currentThread().getName()+"_"+"idx:"+idx+"----");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }



}